package com.gxa.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gxa.stu.common.BizException;
import com.gxa.stu.common.ExceptionCode;
import com.gxa.stu.common.JsonResult;
import com.gxa.stu.entity.dto.ManagerDto;
import com.gxa.stu.entity.pojo.TbManager;
import com.gxa.stu.entity.vo.ManagerVo;
import com.gxa.stu.service.dtoService.ManagerDtoService;
import com.gxa.stu.service.TbManagerService;
import com.gxa.stu.util.ResponeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 员工详情表 前端控制器
 * </p>
 *
 * @author gxa
 * @since 2022-11-03
 */
@RestController
@RequestMapping("/stu/tbManager")
@Api(tags = "员工管理控制器")
public class ManagerController {
    @Reference
    private ManagerDtoService managerDtoService;

    @Reference
    private TbManagerService tbManagerService;

    @PostMapping("/show")
    @ApiOperation("显示员工信息")
    public JsonResult showManager(@RequestBody ManagerVo managerVo){
        IPage<ManagerDto> ipage = managerDtoService.showManager(managerVo);
        return ResponeUtil.success("查询成功",ipage);
    }

    @PostMapping("/add")
    @ApiOperation("添加员工")
    public JsonResult addManager(@RequestBody TbManager tbManager) throws BizException {
        boolean save = tbManagerService.save(tbManager);
        if(save) {
            return ResponeUtil.success("添加成功");
        }
        throw new BizException(ExceptionCode.FAILED_ADD);
    }

    @GetMapping("/getByNum")
    @ApiOperation("根据员工编号查询员工信息")
    public JsonResult selectByNum(@ApiParam(value = "员工编号",required = true) @RequestParam String mgrNum){
        TbManager tbManager = tbManagerService.selectByNum(mgrNum);
        return ResponeUtil.success("查询成功",tbManager);
    }

    @PostMapping("/update")
    @ApiOperation("编辑员工")
    public JsonResult update(@RequestBody TbManager tbManager) throws BizException {
        boolean b = tbManagerService.updateManager(tbManager);
        if (b) {
            return ResponeUtil.success("修改成功");
        }
        throw new BizException(ExceptionCode.FAILED_UPDATE);
    }

}

